package homework;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HomeWork1 {
    public static void main(String[] args) {
        List<Book> list =  new ArrayList<>();
        Book book1 = new Book(1,"西游记",20.0,"人民出版社");
        Book book2 = new Book(2,"水浒传",21.0,"作家出版社");
        Book book3 = new Book(3,"红楼梦",19.0,"上海出版社");
        list.add(book1);
        list.add(book2);
        list.add(book3);
        for (Book book: list){
            System.out.println(book);
        }

        Map<Integer,Book> map = new HashMap<>();
        map.put(book1.getNum(),book1);
        map.put(book2.getNum(),book2);
        map.put(book3.getNum(),book3);
        System.out.println(map);
    }
}
class Book{
    private int num;
    private String name;
    private double price;
    private String press;

    public Book(int num, String name, double price, String press) {
        this.num = num;
        this.name = name;
        this.price = price;
        this.press = press;
    }

    @Override
    public String toString() {
        return "Book{" +
                "num=" + num +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", press='" + press + '\'' +
                '}';
    }

    public int getNum() {
        return num;
    }
}
